<template>
  <div class>
    <el-card class="ep-card ep-search">
      <el-row :gutter="0">

        <el-col :span="2" style="float:right">
          <el-button type="primary" size="small" @click="back">返回</el-button>
        </el-col>
        <el-col :span="3" style="float:right">
          <el-button type="primary" size="small" @click="open">报告模块（A角）</el-button>
        </el-col>
        <el-col :span="2" style="float:right">
          <el-button type="primary" size="small" @click="openFin">财务信息</el-button>
        </el-col>
      </el-row>
    </el-card>
    <el-tabs type="border-card">
      <el-tab-pane label="项目信息">
        <projHandleDisplay ref='projHandleDisplay'></projHandleDisplay>
      </el-tab-pane>
      <el-tab-pane label="反担保措施">
        <oppositeGuarantee ref="oppositeGuarantee" :projectId="projectId"></oppositeGuarantee>
      </el-tab-pane>
      <el-tab-pane label="收费标准">
        <el-table :data="ChargeData" border style="width: 100%" size="mini">
          <el-table-column align="center" width="80">
            <template slot="header">
              <el-button class="el-icon-circle-plus" @click.prevent="ChargeAddRow()"></el-button>
            </template>
            <template slot-scope="scope">
              <el-button size="mini" type="danger" class="el-icon-remove" @click="ChargeHandleDelete(scope.$index, scope.row)"></el-button>
            </template>
          </el-table-column>
          <el-table-column type="index" width="50" label="NO.">
          </el-table-column>

          <el-table-column label="费用类型" align="center">
            <template slot-scope="scope">
              <el-select v-model="scope.row.type" placeholder="请选择">
                <el-option label="评估费" value="1"></el-option>
                <el-option label="担保费" value="2"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="费率(%)" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.rate"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="确认时间" align="center">
            <template slot-scope="scope">
              <el-date-picker v-model="scope.row.updateTime" type="date" style="width: 100%;" placeholder="选择日期">
              </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="确认人" align="center">
            <template slot-scope="scope">
              <el-select v-model="scope.row.createUserId" placeholder="请选择" disabled>
                <el-option v-for="item in users" :key="item.id" :label="item.realName" :value="item.id">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark"></el-input>
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align:center;width:100%;">
          <el-button type="primary" @click="ChargedoSave()">保存</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane label="公司历年合作情况">
      </el-tab-pane>
      <el-tab-pane label="项目经理意见">
        <el-form :model="myOpinion" ref="myOpinion" inline>

          <el-row>

            <el-form-item label="评审结论与建议" required label-width="180px">
              <el-input type="textarea" :rows="5" v-model="myOpinion.content" autocomplete="off" style="width:1000px"></el-input>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="项目经理建议金额(万元)" required label-width="180px">
              <el-input v-model="myOpinion.money">
              </el-input>
            </el-form-item>
            <el-form-item label="建议期限(月)" label-width="180px" required>
              <el-input v-model="myOpinion.deadline"></el-input>
            </el-form-item>
            <el-form-item label="调查日期" label-width="180px" required>
              <el-date-picker v-model="myOpinion.surveytime" type="date" style="width: 100%;" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="是否加急项目" required label-width="180px">
              <el-select v-model="myOpinion.isurgent" placeholder="请选择">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="下一步处理人员" label-width="180px" required>
              <el-select v-model="myOpinion.nextperson" style="width: 100%;" placeholder="请选择">
                <el-option v-for="item in users" :key="item.id" :label="item.realName" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="开会日期" label-width="180px" required>
              <el-date-picker v-model="myOpinion.conferencetime" type="date" style="width: 100%;" placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-row>
          <el-row>
            <el-form-item label="是否下周开会" required label-width="180px">
              <el-select v-model="myOpinion.isnext" placeholder="请选择">
                <el-option label="是" value="1"></el-option>
                <el-option label="否" value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="参会人员" label-width="180px">
              <el-checkbox-group v-model="myOpinion.personlist">
                <el-checkbox label="参会人员A" name="person"></el-checkbox>
                <el-checkbox label="参会人员B" name="person"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>

          </el-row>
          <div style="text-align:center;width:100%;">
            <el-button type="primary" @click="doSave()">保存</el-button>
            <el-button type="success" @click="submit">提交</el-button>
          </div>
        </el-form>
      </el-tab-pane>

    </el-tabs>



    <el-dialog title="报告A角模块" :visible.sync="dialogFormVisible2">

    </el-dialog>
  </div>
</template>
  
  <script>
export default {
  components: {
    projHandleDisplay: require("@/pages/biz/proj/projDisplay/projHandleDisplay.vue")
      .default,
    oppositeGuarantee: require("@/pages/biz/proj/oppositeGuarantee.vue").default,
 
  },
  data() {
    return {
      dialogFinVisible:false,
      entId: "",
      users: [],
      user: {},
      ChargeData: [],
      myOpinion: {
        content: "",
        money: "",
        deadline: "",
        surveytime: new Date(),
        isurgent: "",
        nextperson: "",
        conferencetime: new Date(),
        isnext: "",
        personlist: []
      },
      projectId: "",
      Opinion: {
        id: "",
        workflowInstanceId: "",
        taskTemplateId: "",
        taskWorkitemId: "",
        content: "",
        createUser: "",
        createUserName: "",
        createOrganName: "",
        createDate: "",
        modifyDate: "",
        modifyUser: "",
        taskName: ""
      },
      flowCheck:{
        id:"",
        projId:"",
        nodeCode:"",//节点编号
        nodeName:"",//节点名称
        content:"",//审批意见
        createUserId:"",
        createUserName:"",
        createTime:new Date,
      },
      taskWorkitem: {},
      taskTemplate: {},
      workflowInstance: {},
      taskConclusion: "",
      dialogFormVisible2: false
    };
  },
  computed: {},

    mounted() {
      this.user = JSON.parse(sessionStorage.getItem("user"));
        this.init();
        this.getusers();
        this.loanBusinessInfo();
    },
    methods:{
      //财务信息
    openFin(){
      //this.dialogFinVisible=true;
       this.$router.push({
        path: "/proj/fin",
        query: {
          projectId: this.projectId,
        }
      });
    },
    //打开A角模块
    open() {},
    //获取项目经理意见
    GetmyOpinionList(projectId) {
      let params = {
        projId: projectId
      };
      this.$api
        .formPost(  "/api/biz/projPmOpinion/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            if (res.retBody.list.length > 0) {
              //debugger
              this.myOpinion = res.retBody.list[0];
              this.myOpinion.personlist = res.retBody.list[0].person.split(",");
            }
          }
        });
    },
    //获取收费标准列表
    GetChargeList(projectId) {
      let params = {
        pageNum: 1,
        pageSize: 9999,
        projectid: projectId
      };
      this.$api
        .formPost(  "/api/biz/projCharge/doGetList", params)
        .then(res => {
          if (res.retHead.code === "0000000") {
            this.ChargeData = res.retBody.list;
          }
        });
    },
    //保存收费标准信息
    ChargedoSave() {
      let params = {
        list: this.ChargeData
      };
      this.$api
        .post(  "/api/biz/projCharge/doSaveList", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.$message({
              type: "success",
              message: "保存成功"
            });
          } else {
            this.$message({
              type: "error",
              message: res.retHead.message
            });
          }
        });
    },
    //加载项目信息
    loanBusinessInfo() {
      this.$api
        .post(  "/wf/common/approval?id=" + this.$route.query.id)
        .then(res => {
          if (res.status === "0") {
            if (res.data != null) {
              let projectId = res.data.businessRelation.mid;
              this.projectId = projectId;
              let opinion = res.data.myOpinion;
              this.$refs.oppositeGuarantee.init(projectId);
              this.GetChargeList(projectId);
              this.GetmyOpinionList(projectId);
                    this.flowCheck.projId=this.projectId;
                    this.flowCheck.nodeCode=res.data.taskWorkitem.taskCode;//节点编号
                    this.flowCheck.nodeName=res.data.taskWorkitem.taskName;//节点名称
                //获取当前节点审批意见
                this.$api.formPost( "/api/biz/flowCheck/doGetByNodeCodeAndProjId",{
                  projId:this.projectId,
                  nodeCode:res.data.taskWorkitem.taskCode
                }).then(res => {
                            if (res.retHead.code=='0000000' ) {
                              if(res.retBody!=null){
                                  console.log("测试1");
                                  this.flowCheck=res.retBody;
                                  this.flowCheck.createTime=new Date(res.retBody.createTime);
                                  if(res.retBody.updateTime){
                                    this.flowCheck.updateTime=new Date(res.retBody.updateTime);
                                  }
                                  
                              }else{
                                console.log("测试2");
                               
                                this.flowCheck.content="";//审批意见
                                this.flowCheck.createUserId=this.user.id;
                                this.flowCheck.createUserName=this.user.realName;
                                console.log(this.flowCheck);
                              }
                                  
                            }
                          });
              if (opinion != null && typeof opinion !== "undefined") {
                this.Opinion = {
                  id: opinion.id || "",
                  workflowInstanceId: opinion.workflowInstanceId || "",
                  taskTemplateId: opinion.taskTemplateId || "",
                  taskWorkitemId: opinion.taskWorkitemId || "",
                  content: opinion.content || "",
                  createUser: opinion.createUser || "",
                  createUserName: opinion.createUserName || "",
                  createOrganName: opinion.createOrganName || "",
                  createDate: opinion.createDate || "",
                  modifyDate: opinion.modifyDate || "",
                  modifyUser: opinion.modifyUser || "",
                  taskName: opinion.taskName || ""
                };
              } else {
                this.Opinion.id = "";
                this.Opinion.workflowInstanceId =
                  res.data.taskWorkitem.workflowInstanceId;
                this.Opinion.taskTemplateId =
                  res.data.taskWorkitem.taskTemplateId;
                this.Opinion.taskWorkitemId = res.data.taskWorkitem.id;
                //content从前端接受
                this.Opinion.createUser = this.user.id;
                this.Opinion.createUserName = this.user.realName;
                this.Opinion.createOrganName = "";
                this.Opinion.createDate = new Date();
                this.Opinion.modifyDate = new Date();
                this.Opinion.modifyUser = this.user.id;
                this.Opinion.taskName = res.data.taskWorkitem.taskName;
              }
              if (res.data.taskWorkitem != null) {
                this.taskWorkitem = res.data.taskWorkitem;

                if (this.taskWorkitem.taskConclusion != null) {
                  this.taskConclusion = this.taskWorkitem.taskConclusion || "";
                }
              }

              if (res.data.workflowInstance != null) {
                this.workflowInstance = res.data.workflowInstance;
              }

              if (res.data.taskTemplate != null) {
                this.taskTemplate = res.data.taskTemplate;
              }
              this.$refs.projHandleDisplay.innit(projectId);
            }
          }
        });
    },
    getusers() {
      let params = {};
      this.$api
        .formPost(  "/api/auth/sysuser/doGetList", params)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.users = res.retBody.list;
          }
        });
    },
    //增加收费标准一行
    ChargeAddRow() {
      var list = {
        type: "1",
        projectid: this.projectId,
        createUserName: this.user.realName,
        updateTime: new Date(),
        createUserId: this.user.id
      };
      this.ChargeData.unshift(list);
    },
    //删除收费标准一行
    ChargeHandleDelete(index, row) {
      this.ChargeData.splice(index, 1);
    },
    back() {
      this.$router.push({ path: "/mywork/taskLog" });
    },
    init() {},
    //保存项目经理意见
    doSave() {
      this.myOpinion.projId = this.projectId;
      this.myOpinion.createUserId = this.user.id;
      this.myOpinion.createUserName = this.user.realName;
      this.$api
        .formPost(  "/api/biz/projPmOpinion/doSave", this.myOpinion)
        .then(res => {
          if (res.retHead.code == "0000000") {
            this.flowCheck.content = this.myOpinion.content;

            //保存意见到本地
            this.$api.formPost( "/api/biz/flowCheck/doSave",this.flowCheck).then(res => {
                  if(res.retHead.code=="0000000"){
                      this.$message({
                          type: "success",
                          message: "保存成功"
                        });
                  }
            });
            // 先保存工作流意见，再提交流程
            // this.$api.post(  "/wf/opinion/save", this.Opinion).then(res => {
            //   if (res.status === "0") {
            //     this.$message({
            //       type: "success",
            //       message: "保存成功"
            //     });
            //   }
            // });

            this.loanBusinessInfo();
          } else {
            this.$message({
              type: "error",
              message: res.retHead.message
            });
          }
        });
    },
    //提交
    submit() {
      let params = {};
      params.taskWorkitemId = this.taskWorkitem.id;
      params.isSubmit = "1";
      params.userId = this.user.id;
      params.variables = {
        isurgent: this.myOpinion.isurgent,
        nextperson: this.myOpinion.nextperson
      };
      this.$api.post(  "/wf/submit", params).then(res => {
        if (res.status === "0") {
          this.$message({
            type: "success",
            message: "保存成功!"
          });

          if (params.isSubmit) {
            this.$router.push({
              path: "/mywork/taskLog"
            });
          } else {
            this.getBusinessInfo();
          }
        }
      });
    }
  },
  created() {}
}
</script>
  <style lang='scss' scoped>
</style>